// 根据运动种类id查询当前运动赛事阶段名称和联赛级别
import { api_system } from "src/api/index.js";
export default {
  state: {
    match_data: {},
    sportId: "" //根据运动id储存数据
  },
  getters: {
    get_match_data(state) {
      return state.match_data;
    },
    get_sportId(state) {
      return state.sportId;
    }
  },
  mutations: {
    set_match_data(state, match_data) {
      state.match_data = match_data;
    },
    set_sportId(state, sportId) {
      state.sportId = sportId;
    }
  },
  actions: {
    // 调用挂载到keyWord对象下params比如{keword: 1}根据跟后台格式把赛事状态和等级挂载下
    set_match_data({ commit, dispatch }, params) {
      api_system.post_systemtypedict(params).then(res => {
        const {
          data: { code }
        } = res;
        if (code == 200) {
          const {
            data: {
              data: { matchStatus, tournamentLevel }
            }
          } = res;
          function returnValue(params) {
            let arr = [];
            if (Array.isArray(params) && params.length > 0) {
              arr = [...params];
              arr.unshift({
                value: "",
                description: "全部"
              });
            }
            return arr;
          }
          commit("set_sportId", params.keyWord);
          commit("set_match_data", { matchStatus, tournamentLevel });
          dispatch("set_allMatchStaus", {
            sportId: params.keyWord,
            key: "match_status_constant",
            arr: returnValue(matchStatus)
          });
          dispatch("set_allMatchStaus", {
            sportId: params.keyWord,
            key: "match_level_constant",
            arr: returnValue(tournamentLevel)
          });
        }
      });
    },
    set_sportId({ commit }, sportId) {
      scommit("set_sportId", sportId);
    }
  }
};
